#!/bin/bash

# Nginx 配置重载脚本
# 使用方法: chmod +x reload_nginx.sh && ./reload_nginx.sh

echo "=========================================="
echo "  重新加载 Nginx 配置"
echo "=========================================="
echo ""

cd /Users/muzhou/code/pecco-pet-shop

echo "✓ 步骤 1: 测试 Nginx 配置语法..."
docker-compose exec nginx nginx -t

if [ $? -eq 0 ]; then
    echo "  ✅ 配置语法正确"
    echo ""
    
    echo "✓ 步骤 2: 重新加载 Nginx 配置..."
    docker-compose exec nginx nginx -s reload
    
    if [ $? -eq 0 ]; then
        echo "  ✅ Nginx 配置已重新加载成功！"
        echo ""
        
        echo "✓ 步骤 3: 验证服务状态..."
        docker-compose ps nginx
        echo ""
        
        echo "=========================================="
        echo "  ✅ 完成！"
        echo "=========================================="
        echo ""
        echo "📝 现在可以进行以下操作："
        echo "1. 访问 https://www.pecco.pet 确认可以访问"
        echo "2. 查看页面源代码，确认包含验证 meta 标签"
        echo "3. 在百度站长平台点击'完成验证'"
        echo ""
    else
        echo "  ❌ 重新加载失败"
        echo ""
        echo "查看详细日志:"
        docker-compose logs --tail=50 nginx
    fi
else
    echo "  ❌ 配置语法错误，请检查 nginx.conf"
    echo ""
    echo "建议:"
    echo "1. 检查配置文件语法"
    echo "2. 查看错误信息修复问题"
    echo "3. 重新运行此脚本"
fi

